#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100

typedef struct{
  int data[MAX_SIZE];
  int top;
}Stack;

void initStack(Stack *stack){
  stack->top=-1;
}

int isEmpty(Stack *stack){
  return stack->top == -1;
}

int isFull(Stack *stack){
  return stack->top == MAX_SIZE-1;
}

void push(Stack *stack,int value){
  if(isFull(stack)){
    printf("栈以满，无法入栈\n");
    return;
  }
  stack->data[++stack->top]=value;
}

int pop(Stack *stack){
  if(isEmpty(stack)){
    printf("栈为空，无法出栈\n");
    return -1;
  }
  return stack->data[stack->top--];
}

int peek(Stack *stack){
  if(isEmpty(stack)){
    printf("栈为空，无栈顶元素\n");
    return -1;
  }
  return stack->data[stack->top];
}

int main(){
  Stack stack;
  initStack(&stack);
  printf("栈是否为空：%s\n",isEmpty(&stack)?"是":"否");
  push(&stack,1);
  push(&stack,2);
  push(&stack,3);
  printf("栈顶元素：%d\n",peek(&stack));
  printf("出栈元素：%d\n",pop(&stack));
  printf("栈顶元素：%d\n",peek(&stack));
  printf("栈是否为空：%s\n",isEmpty(&stack)?"是":"否");
  return 0;
}